import { ElMessage } from 'element-plus'
import { isEmpty } from '@/utils/toolsValidate'
import { orderHurry, orderStart, allFoodOrderServe, foodStartTicketPrint, unOrderPresent, addWriteFood } from '@/api/food'
import { orderFoodDetail, orderFoodEditNum, editMemberPrice, orderFoodBatchBack } from '@/api/desktop'
import messageTips from '@/components/messageTips'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {orderFoodStart} from '@/api/food'
// 菜品右侧操作相关的hook
export function useFoodActions() {

    const router = useRouter()
    const showFullReturnFoodDialog = ref(false)
    // 全单退菜处理
    const handleFullReturnFood = async () => {
        // 触发全单退菜原因选择弹窗
        // emit('showFullReturnFoodDialog', currentDeskDetail)
        showFullReturnFoodDialog.value = true
    }

    const handleShowFoodSeatsDialog = async (currentDeskDetail: any, emit: any) => {
         try{
            const messageInstance = await messageTips.message(
                {
                    title: '起菜',
                    content: `确定要对[${currentDeskDetail.name}]桌进行菜品席数调整吗？`,
                    isOnCancel: true,
                    onCancelText: '取消',
                    onSumbitText: '确定'
                },
                async () => {
                    try {
                        const params = {
                            id: currentDeskDetail.id,
                            num: currentDeskDetail.num
                        }
                        const res = await orderFoodStart(params)
                        if (res.status === 200) {
                            ElMessage.success('起菜成功')
                            emit('refreshData')
                            emit('refreshDesk')
                        } else {
                            ElMessage.error('起菜失败')
                        }
                    } catch (error) {
                        console.error('起菜失败:', error)
                        ElMessage.error('起菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                },
            )
         } catch(error){
            // 这里处理的是弹窗被关闭的情况（比如点击遮罩层关闭）
            console.log('弹窗被关闭:', error)
         }
            
    }
    // 全单催菜处理
    const handleFullUrgeCook = async (currentDeskDetail: any, emit: any) => {
        try {
            const messageInstance = await messageTips.message(
                {
                    title: '全单催菜',
                    content: '您确定要进行全单催菜，并远程打印催菜单吗？',
                    isOnCancel: true,
                    onCancelText: '只催菜',
                    onSumbitText: '全单催菜并打印'
                },
                // 确认回调：全单催菜并打印
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            print: 1, // 全单催菜并打印
                            record_id: currentDeskDetail.id
                        }

                        const res = await orderHurry(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '全单催菜成功')
                            // 通知父组件刷新数据
                            emit('refreshData')
                            emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '全单催菜失败')
                        }
                    } catch (error) {
                        console.error('全单催菜失败:', error)
                        ElMessage.error('全单催菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                },
                // 取消回调：只催菜
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            print: 0, // 只催菜，不打印
                            record_id: currentDeskDetail.id
                        }

                        const res = await orderHurry(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '催菜成功')
                            // 通知父组件刷新数据
                            emit('refreshData')
                            emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '催菜失败')
                        }
                    } catch (error) {
                        console.error('催菜失败:', error)
                        ElMessage.error('催菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                }
            )
        } catch (error) {
            // 这里处理的是弹窗被关闭的情况（比如点击遮罩层关闭）
            console.log('弹窗被关闭:', error)
        }
    }

    // 全单起菜处理
    const handleFullStartCook = async (currentDeskDetail: any, emit: any) => {

        try {
            const messageInstance = await messageTips.message(
                {
                    title: '全单起菜',
                    content: '您确定要起菜，并远程打印起菜通知单吗？',
                    isOnCancel: true,
                    onCancelText: '全单起菜不打印',
                    onSumbitText: '全单起菜并打印'
                },
                // 确认回调：全单起菜并打印
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            print: 1, // 全单起菜并打印
                            record_id: currentDeskDetail.id
                        }

                        const res = await orderStart(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '全单起菜成功')
                            // 通知父组件刷新数据
                            emit('refreshData')
                            emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '全单起菜失败')
                        }
                    } catch (error) {
                        console.error('全单起菜失败:', error)
                        ElMessage.error('全单起菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                },
                // 取消回调：全单起菜不打印
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            print: 0, // 全单起菜不打印
                            record_id: currentDeskDetail.id
                        }

                        const res = await orderStart(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '起菜成功')
                            // 通知父组件刷新数据
                            emit('refreshData')
                            emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '起菜失败')
                        }
                    } catch (error) {
                        console.error('起菜失败:', error)
                        ElMessage.error('起菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                }
            )
        } catch (error) {
            // 这里处理的是弹窗被关闭的情况（比如点击遮罩层关闭）
            console.log('弹窗被关闭:', error)
        }
    }

    // 全单等叫弹框状态
    const showWaitDialog = ref(false)
    // 全单等叫处理 弹框状态
    const handleFullWait = (currentDeskDetail: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return null
        }
        showWaitDialog.value = true
    }

    // 全单赠送弹框状态
    const showGiftDialog = ref(false)
    // 全单赠送处理 弹框状态
    const handleFullGift = (currentDeskDetail: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return null
        }
        showGiftDialog.value = true
    }

    // 菜品转台弹框状态
    const showTransferDialog = ref(false)
    // 菜品转台处理 弹框状态
    const handleFoodTransfer = (currentDeskDetail: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return null
        }
        showTransferDialog.value = true
    }

    // 规格/数量 弹框状态与数据
    const showSpecQuantityDialog = ref(false)
    const specFoodData = ref<any>(null)
    const handleSpecQuantity = async (currentDeskDetail: any, emit: any, selectFoodActiveIndex: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return
        }
        if (selectFoodActiveIndex === -1) {
            ElMessage.warning('请先选择菜品')
            return
        }
        const selectedFood = currentDeskDetail.foodList?.[selectFoodActiveIndex]
        if (!selectedFood) {
            ElMessage.warning('选中的菜品信息异常')
            return
        }
        // 拉取下单后的详情用于回显（与下单前保持一致的结构）
        try {
            const res = await orderFoodDetail({ id: selectedFood.id })
            if (res.status === 200) {
                const food = res.data.food || {}
                // 标准化回显结构：包含 skuList、skuInfo、num
                const payload = {
                    ...selectedFood,
                    skuList: food.skuList || selectedFood.skuList || [],
                    skuInfo: selectedFood.skuInfo || food.skuInfo || {},
                    num: res.data.num ?? selectedFood.num ?? 1,
                    spec_type: food.spec_type ?? selectedFood.spec_type
                }
                specFoodData.value = payload
            } else {
                specFoodData.value = { ...selectedFood, num: selectedFood.num ?? 1 }
            }
        } catch (e) {
            specFoodData.value = { ...selectedFood, num: selectedFood.num ?? 1 }
        }
        showSpecQuantityDialog.value = true
    }
    const specQuantityLoading = ref(false)
    // 规格/数量确认（下单后：提交修改数量/规格）
    const onSpecConfirm = async (payload: any, emit: any) => {
        try {
            if (!specFoodData.value || !specFoodData.value.id) {
                ElMessage.warning('当前菜品信息异常')
                return
            }

            const num = parseInt(payload?.num)
            if (isNaN(num) || num <= 0) {
                ElMessage.warning('请输入有效的数量')
                return
            }

            const params: any = {
                id: specFoodData.value.id,
                num
            }
            if (payload?.food_sku_id) {
                params.food_sku_id = payload.food_sku_id
            }
            specQuantityLoading.value = true

            const res = await orderFoodEditNum(params)
            if (res.status === 200) {
                ElMessage.success(res.data?.message || '修改成功')
                showSpecQuantityDialog.value = false
                emit && emit('refreshData')
                emit && emit('refreshDesk')
            } else {
                ElMessage.error(res.data?.message || '修改失败')
            }
        } catch (error) {
            console.error('规格/数量修改失败: ', error)
            ElMessage.error('修改失败')
        } finally {
            specQuantityLoading.value = false
        }
    }

    // 全单打折（右侧直接做，不区分单品）
    const showFullDiscountDialog = ref(false)
    const handleFullDiscount = (currentDeskDetail: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return
        }
        showFullDiscountDialog.value = true
    }

    // 开启会员价（增加确认弹框）
    const handleOpenMemberPrice = async (currentDeskDetail: any, emit: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return
        }
        try {
            const messageInstance = await messageTips.message(
                {
                    title: '开启会员价',
                    content: '确定要为该桌台开启会员价吗？',
                    isOnCancel: true,
                    onSumbitText: '确定'
                },
                // 确认回调
                async () => {
                    try {
                        messageInstance.setLoading(true)
                        const res = await editMemberPrice({ status: 1, record_id: currentDeskDetail.id })
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '开启会员价成功')
                            emit && emit('refreshData')
                            emit && emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '开启会员价失败')
                        }
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                }
            )
        } catch (error) {
            // 关闭弹框等
        }
    }

    // 关闭会员价
    const handleCloseMemberPrice = async (currentDeskDetail: any, emit: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return
        }
        try {
            const messageInstance = await messageTips.message(
                {
                    title: '关闭会员价',
                    content: '确定要关闭该桌台的会员价吗？',
                    isOnCancel: true,
                    onSumbitText: '确定'
                },
                async () => {
                    try {
                        messageInstance.setLoading(true)
                        const res = await editMemberPrice({ status: 0, record_id: currentDeskDetail.id })
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '关闭会员价成功')
                            emit && emit('refreshData')
                            emit && emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '关闭会员价失败')
                        }
                    } catch (error) {
                        console.error('关闭会员价失败:', error)
                        ElMessage.error('关闭会员价失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                }
            )
        } catch (error) { }
    }

    // 根据当前桌台全单赠送状态，切换为 全单赠送 / 全单撤赠
    const handleToggleFullPresent = async (currentDeskDetail: any, emit: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return
        }
        const foodList = currentDeskDetail?.foodList || []
        const hasFoods = Array.isArray(foodList) && foodList.length > 0
        const isAllPresented = hasFoods && foodList.every((f: any) => f?.is_present === 1 || f?.is_present === 2)

        if (isAllPresented) {
            // 全单撤赠
            try {
                const messageInstance = await messageTips.message(
                    {
                        title: '全单撤赠',
                        content: '确定要撤销全单赠送吗？',
                        isOnCancel: true,
                        onSumbitText: '确定'
                    },
                    async () => {
                        try {
                            messageInstance.setLoading(true)
                            const res = await unOrderPresent({ record_id: currentDeskDetail.id })
                            if (res.status === 200) {
                                ElMessage.success(res.data?.message || '撤销成功')
                                emit && emit('refreshData')
                                emit && emit('refreshDesk')
                            } else {
                                ElMessage.error(res.data?.message || '撤销失败')
                            }
                        } catch (e) {
                            ElMessage.error('撤销失败')
                        } finally {
                            messageInstance.setLoading(false)
                            messageInstance.close && messageInstance.close()
                        }
                    }
                )
            } catch (e) { }
        } else {
            // 打开全单赠送弹框
            showGiftDialog.value = true
        }
    }

    // 重打处理
    const handleReprint = async (currentDeskDetail: any, emit: any, selectFoodActiveIndex: any) => {
        if (!currentDeskDetail) {
            ElMessage.warning('请先选择桌台')
            return
        }

        // 检查是否选择了菜品
        if (selectFoodActiveIndex === -1) {
            ElMessage.warning('请先选择菜品')
            return
        }

        // 获取选中的菜品信息
        const selectedFood = currentDeskDetail.foodList?.[selectFoodActiveIndex]

        if (!selectedFood) {
            ElMessage.warning('选中的菜品信息异常')
            return
        }

        try {
            const messageInstance = await messageTips.message(
                {
                    title: '重打',
                    content: `确定重新打印（${selectedFood.name || '酒席'}）吗？`,
                    isOnCancel: true,
                    onCancelText: '全单重打',
                    onSumbitText: '单菜打印'
                },
                // 确认回调：单个菜品重打
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            food_id: selectedFood.id,
                            order_id: currentDeskDetail.order_id
                        }

                        const res = await foodStartTicketPrint(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '发起打印成功')
                        } else {
                            ElMessage.error(res.data?.message || '重打失败')
                        }
                    } catch (error) {
                        console.error('重打失败:', error)
                        ElMessage.error('重打失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                },
                // 取消回调：全单重打
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            order_id: currentDeskDetail.order_id
                        }

                        const res = await foodStartTicketPrint(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '全单重打成功')
                        } else {
                            ElMessage.error(res.data?.message || '全单重打失败')
                        }
                    } catch (error) {
                        console.error('全单重打失败:', error)
                        ElMessage.error('全单重打失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                }
            )
        } catch (error) {
            // 这里处理的是弹窗被关闭的情况（比如点击遮罩层关闭）
            console.log('弹窗被关闭:', error)
        }
    }

    // 全单上齐处理
    const handleFullServedFood = async (currentDeskDetail: any, emit: any) => {
        try {
            const messageInstance = await messageTips.message(
                {
                    title: '全单上齐',
                    content: '您确定此桌台的菜品已经全部上齐了吗？',
                    isOnCancel: true,
                    onCancelText: '取消',
                    onSumbitText: '确定'
                },
                // 确认回调：全单上齐
                async () => {
                    try {
                        messageInstance.setLoading(true)

                        const params = {
                            record_id: currentDeskDetail.id
                        }

                        const res = await allFoodOrderServe(params)
                        if (res.status === 200) {
                            ElMessage.success(res.data?.message || '全单上齐成功')
                            // 通知父组件刷新数据
                            emit('refreshData')
                            emit('refreshDesk')
                        } else {
                            ElMessage.error(res.data?.message || '全单上齐失败')
                        }
                    } catch (error) {
                        console.error('全单上齐失败:', error)
                        ElMessage.error('全单上齐失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                }
            )
        } catch (error) {
            // 这里处理的是弹窗被关闭的情况（比如点击遮罩层关闭）
            console.log('弹窗被关闭:', error)
        }
    }

    // 点击操作栏事件
    const handleActionBar = (
        index: number,
        currentDeskDetail: any,
        selectFoodActiveIndex: any,
        actionsList: any,
        emit: any
    ) => {
        console.log('点击操作栏:', index, actionsList?.[index], currentDeskDetail)

        const currentAction = actionsList?.[index]

        // 选择了桌台才能操作
        if (isEmpty(currentDeskDetail)) {
            ElMessage.warning('请先选择桌台')
            return
        }


        // 没有菜品列表不让点击
        if (
            isEmpty(currentDeskDetail?.foodList) &&
            isEmpty(currentDeskDetail?.feastFoodList) && index !== 0
        ) {
            ElMessage.warning('请先点菜下单')
            return
        }

        // 需要选择菜品才能进行操作的判断
        if (currentAction?.needSelectFood && selectFoodActiveIndex === -1) {
            ElMessage.warning('请先选择菜品')
            return
        }

        if (currentAction?.fun) {
            currentAction?.fun(currentDeskDetail, emit, selectFoodActiveIndex)
            return
        }

        ElMessage.info(`执行操作: ${currentAction?.name || '未知操作'}`)
    }
    // const showFoodPracticeDialog = ref(false)
    //
    const handleShowPracticeFood = (currentDeskDetail: any, emit: any, selectFoodActiveIndex: any) => {
        emit('openPractice', selectFoodActiveIndex, currentDeskDetail)
    }
    // 点菜跳转
    const handleShowFood = async (currentDeskDetail: any) => {
        // emit('openFood', selectFoodActiveIndex, currentDeskDetail)
        // 判断是不是已经预结了 如果是给他是 先关闭预结
        if (currentDeskDetail.is_lock.value === 2) {
            ElMessage.warning('当前桌台已预结，请先关闭预结')
            return
        }
        // 判断是不是普通点菜

        const isNormal = [10, 20].includes(currentDeskDetail.open_type?.value)
        if (isNormal) {
            router.push({
                path: '/home/diancai/' + currentDeskDetail.id,
                query: {
                    type: 1
                }
            })
        } else {
            // 需要给提示
            const messageInstance = await messageTips.message({
                title: '提示',
                content: '当前桌台为多台开席，请先选择点菜方式',
                isOnCancel: true,
                onSumbitText: '本桌点菜',
                onCancelText: '全席点菜',

            },
                async () => {
                    try {
                        messageInstance.setLoading(true)
                        router.push({
                            path: '/home/diancai/' + currentDeskDetail.id,
                            query: {
                                type: 1
                            }
                        })
                    } catch (error) {
                        console.error('全席点菜失败:', error)
                        ElMessage.error('全席点菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                },
                async () => {
                    try {
                        messageInstance.setLoading(true)
                        router.push({
                            path: '/home/diancai/' + currentDeskDetail.id,
                            query: {
                                type: 2
                            }
                        })
                    } catch (error) {
                        console.error('本卓点菜失败:', error)
                        ElMessage.error('本卓点菜失败')
                    } finally {
                        messageInstance.setLoading(false)
                        messageInstance.close && messageInstance.close()
                    }
                })
        }
    }


    // 手写菜品
    const showHandwritingFoodDialog = ref(false)
    const handleWriteFood =  () => {
        showHandwritingFoodDialog.value = true
    }

    // 菜品席数相关
    const showFoodSeatsDialog = ref(false)
    const handleFoodSeats = (currentDeskDetail: any, selectCurrentFoodData: any) => {
        // 判断是否是酒席套装
        if (
            currentDeskDetail?.settle_type?.value === 10 &&
            !isEmpty(selectCurrentFoodData?.feastFoodList)
        ) {
            ElMessage.warning('酒席菜品不可进行菜品席数的调整操作')
            return
        }
        showFoodSeatsDialog.value = true
    }

    const addHandwritingFood = async (handwritingFoodData: any, currentDeskDetail: any, emit: any) => {
        const isNormal = [10, 20].includes(currentDeskDetail.open_type?.value)
        const formData = {
            record_id: currentDeskDetail.id,
            belong_type: isNormal ? 2 : 1,
            food_list: [
                {
                    food_sku_id: handwritingFoodData.food_sku_id,
                    num: handwritingFoodData.foodNum,
                    write_food_name: handwritingFoodData.write_food_name, 
                    write_food_price: handwritingFoodData.write_food_price 
                }
            ]
        }
        const res = await addWriteFood(formData)
        if (res.status === 200) {
            ElMessage.success(res.data?.message || '添加手写菜品成功')
            emit('refreshData')
            emit('refreshDesk')
        } else {
            ElMessage.error(res.data?.message || '添加手写菜品失败')
        }
    }


    // 菜品的操作按钮相关列表
    const actionsList = ref([
        { key: 'showFood', name: '点菜', needSelectFood: false, fun: handleShowFood },
        { key: 'fullReturn', name: '全单退菜', needSelectFood: false, fun: handleFullReturnFood },
        { key: 'fullUrge', name: '全单催菜', needSelectFood: false, fun: handleFullUrgeCook },
        { key: 'fullWait', name: '全单等叫', needSelectFood: false, fun: handleFullWait },
        { key: 'fullStart', name: '全单起菜', needSelectFood: false, fun: handleFullStartCook },
        { key: 'toggleFullPresent', name: '全单赠送', needSelectFood: false, fun: (desk: any, emit: any) => handleToggleFullPresent(desk, emit) },
        { key: 'fullServed', name: '全单上齐', needSelectFood: false, fun: handleFullServedFood },
        { key: 'writeFood', name: '手写菜品', needSelectFood: false, fun: handleWriteFood },
        { key: 'reprint', name: '重打', needSelectFood: true, fun: handleReprint },
        { key: 'multiSeats', name: '菜品席数', needSelectFood: true, fun: (desk: any, emit: any, selectFoodActiveIndex: number) => handleFoodSeats(desk, desk?.foodList?.[selectFoodActiveIndex]) },
        { key: 'transfer', name: '菜品转台', needSelectFood: false, fun: handleFoodTransfer },
        { key: 'specQuantity', name: '规格/数量', needSelectFood: true, fun: handleSpecQuantity },
        { key: 'practice', name: '修改做法', needSelectFood: true, fun: handleShowPracticeFood },
        { key: 'fullDiscount', name: '全单打折', needSelectFood: false, fun: handleFullDiscount },
        {
            key: 'memberPrice', name: '开启会员价', needSelectFood: false, fun: (desk: any, emit: any) => {
                const isVipOn = desk?.is_vip === 1 || desk?.discountInfo?.is_vip === 1
                return isVipOn ? handleCloseMemberPrice(desk, emit) : handleOpenMemberPrice(desk, emit)
            }
        }
    ])

    // 基于当前桌台状态动态调整文案（全单赠送/撤赠，开启/关闭会员价）
    const getActionsRenderList = (currentDeskDetail: any) => {
        const foodList = currentDeskDetail?.foodList || []
        const hasFoods = Array.isArray(foodList) && foodList.length > 0
        const isAllPresented = hasFoods && foodList.every((f: any) => f?.is_present === 1 || f?.is_present === 2)
        const isVipOn = currentDeskDetail?.is_vip === 1 || currentDeskDetail?.discountInfo?.is_vip === 1
        const hasMember = !!(currentDeskDetail?.user && (currentDeskDetail.user.grade || currentDeskDetail.user.id))
        // 多台开席（酒席）判定：open_type.value === 50 且 open_num > 1
        const isMultiOpen = currentDeskDetail?.open_type?.value === 50 && Number(currentDeskDetail?.open_num) > 1

        let newActiveActions = actionsList.value.map(item => {
            // 全单赠送/撤赠
            if (item.key === 'toggleFullPresent') {
                return { ...item, name: isAllPresented ? '全单撤赠' : '全单赠送' }
            }
            // 开启/关闭会员价
            if (item.key === 'memberPrice') {
                return { ...item, name: isVipOn ? '关闭会员价' : '开启会员价', disabled: !hasMember }
            }
            // 菜品席数：非多台开席时置灰
            if (item.key === 'multiSeats') {
                return { ...item, disabled: !isMultiOpen }
            }
            if (item.key === 'specQuantity' || item.key === 'practice') {
                return { ...item, disabled: !isMultiOpen }
            }
            return item
        })
        return newActiveActions
    }
    return {
        handleActionBar,
        handleFullReturnFood,
        handleFullUrgeCook,
        handleFullStartCook,
        handleFullWait,
        handleFullGift,
        handleFoodTransfer,
        handleReprint,
        handleFullServedFood,
        handleSpecQuantity,
        handleFullDiscount,
        handleOpenMemberPrice,
        handleCloseMemberPrice,
        handleToggleFullPresent,
        showFullReturnFoodDialog,
        showWaitDialog,
        showGiftDialog,
        showTransferDialog,
        showSpecQuantityDialog,
        specFoodData,
        showFullDiscountDialog,
        actionsList,
        getActionsRenderList,
        onSpecConfirm,
        specQuantityLoading,
        showHandwritingFoodDialog,
        addHandwritingFood,
        showFoodSeatsDialog,
        handleShowFoodSeatsDialog
    }
}
